import ili9341
import network
import time
from machine import Pin, SPI
from socket import *

#画笔颜色
WHITE = 0xFFFF #白色
BLACK = 0x0000 #黑色
BLUE  = 0x001F #蓝色
BRED  = 0XF81F
GRED  = 0XFFE0
GBLUE = 0X07FF
RED   = 0xF800 #红色
MAGENTA = 0xF81F #紫红色
GREEN   = 0x07E0 #绿色
CYAN    = 0x7FFF #青色
YELLOW  = 0xFFE0 #黄色
BROWN   = 0XBC40 #棕色
BRRED   = 0XFC07 #棕红色
GRAY    = 0X8430 #灰色

#GUI颜色
DARKBLUE  = 0X01CF #深蓝色
LIGHTBLUE = 0X7D7C #浅蓝色
GRAYBLUE  = 0X5458 #灰蓝色
#以上三色为PANEL的颜色 

LIGHTGREEN  = 0X841F #浅绿色
LIGHTGRAY   = 0XEF5B #浅灰色(PANNEL)
LGRAY       = 0XC618 #浅灰色(PANNEL),窗体背景色

LGRAYBLUE   = 0XA651 #浅灰蓝色(中间层颜色)
LBBLUE      = 0X2B12 #浅棕蓝色(选择条目的反色)

LCD_WIDTH = 10
LCD_HEIGHT = 12

spi = SPI(miso=Pin(19), mosi = Pin(23, Pin.OUT), sck = Pin(18, Pin.OUT))
display = ili9341.ILI9341(spi, cs = Pin(14), dc = Pin(27), rst = Pin(33), bl=Pin(32))

# 连接热点
def do_connect():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...')
        wlan.connect('meik30', '5201314ygyu')  # 配置热点名称和密码
        i = 1
        while not wlan.isconnected():
            print("正在链接...{}".format(i))
            i += 1
            time.sleep(1)
    print('network config:', wlan.ifconfig())

do_connect()


def introd_data():
    image_list = []
    image_data = socket(AF_INET, SOCK_DGRAM, 0)  # udp接受视频流
    addr = ('0.0.0.0', 7788)
    image_data.bind(addr)
    while True:
        data, _ = image_data.recvfrom(8000)  # udp接受视频数据
#         print(data)
#         display.image(0, 0, LCD_WIDTH, LCD_HEIGHT, data)
        if len(data) != 0:
            image_list.extend(data)
            print(image_list)
#             display.image( 0, 0, LCD_WIDTH, LCD_HEIGHT, image_list, True)

if __name__ == '__main__':
    introd_data()
































